<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller {
    //前台登录页面
    public function login(){
    	$this->display();
    }
    //前台注册页面
    public function reg(){
    	$this->display();
    }
    //注册手机确认页
    public function reg_qr()
    {
    	$this->display();
    }
    //账号设置
    public function settings()
    {
        $this->display();
    }

    //安全设置
    public function anquan()
    {
        $this->display();
    }
    public function dologin()
    {
        //实例化model类
        $user = M('user');

        $username = I('post.username');

        //查询数据库是否有此用户名
        $res = $user->where("status = 1 and username = '$username'")->select();
        if($res){
            echo 1;
        }else{
            echo 2;
        }
    }

    //用户登录
    public function gologin()
    {
        //实例化model类
        $user = M('user');

        //接收前台用户和密码
        $username = I('post.username');
        $userpwd  = I('post.userpwd');

        //进行数据库查询
        $res = $user->where("username='$username' and userpwd = '$userpwd'") ->select();
        if($res){
            session('username',$res[0]['username']);
            session('user_id',$res[0]['id']);
            $this->success('登录成功',session('url'),1);
        }else{
            $this->error('账户或密码错误，登录失败');
        }
    }

    //退出登录
    public function out()
    {
       session_unset();
       session_destroy();
       $this->success('退出成功',U('index/index'),1);
    }

}